//03errno_new.c

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <linux/limits.h>
#include "rocerror.h"

int main(int argc, char *argv[])
{
    char filename[PATH_MAX] = {0};

    if (argc != 2)
    {
        fprintf(stderr, "You must supply a filename as an argument \n");
        return 1;
    }

    strncpy(filename, argv[1], sizeof(filename) - 1);
    filename[sizeof(filename) - 1] = '\0';

    if (creat(filename, 0644) == -1)
    {
        if (errno == EACCES)
        {
            posix_error(EACCES, "Permission check failed");
        }
        else if (errno == ENOENT)
        {
            posix_error(ENOENT, "Path not exists");
        }
        else
        {
            unix_error("Unexpected error occurred");
        }
    }

    return 0;
}